package org.dzl.springboot001.config;


import org.dzl.springboot001.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ResourceBundle;

/**
 * @author 光的代言人
 */
@Configuration
public class MyInterceptorConfig implements WebMvcConfigurer {
    @Value("${uploadPath1}")
    private String uploadPath1;
    @Value("${uploadPath2}")
    private String uploadPath2;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截所有请求
        // 只要地址是 /admin/** 开始，就会被拦截
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/admin/**").excludePathPatterns("/admin/login");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //映射虚拟路径
//        String uploadPath = ResourceBundle.getBundle("application.yml").getString("uploadPath");
        System.out.println(uploadPath1);
        registry.addResourceHandler("/pic1/**").addResourceLocations(uploadPath1);
        registry.addResourceHandler("/pic2/**").addResourceLocations(uploadPath2);
    }
}
